<template>
  <div >
    <div style="line-height: 50px;">
      <div style="font-size: 18px;">借阅审核{{ "   " + date +"/"+ time }}</div>
    <el-table :data="tableDataBorrow" border style="width: 100%" :row-class-name="tableRowClassName">
        <el-table-column prop="username" label="借阅用户" width="130" align="center">
        </el-table-column>
        <el-table-column prop="bookName" label="借阅书籍" width="130" align="center">
        </el-table-column>
        <el-table-column prop="bookId" label="书籍编号" width="130" align="center">
        </el-table-column>
        <el-table-column prop="borrowTime" label="借阅时间" width="200" align="center">
        </el-table-column>
        <el-table-column prop="returnTime" label="归还期限" width="200" align="center">
        </el-table-column>
        <el-table-column label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button type="success" size="mini" @click="agree(scope.row.id)">同意</el-button>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <el-pagination background layout="total,sizes,prev,pager,next,jumper"
      @size-change="handleSizeChange1"
      @current-change="handleCurrentChange1"
      :total="total1"
      :current-page="currentPage1"
      :page-size="pageSize1"
      :page-sizes="[5,10,15,20,30,40,50]"></el-pagination>
    </div>
    <br>
    <hr>
    <br>
    <div style="line-height: 50px;">
      <div style="font-size: 18px;">还书审核{{ "   " + date +"/"+ time }}</div>
      <el-table :data="tableDataReturn" border style="width: 100%" :row-class-name="tableRowClassName">
        <el-table-column prop="username" label="借阅用户" width="130" align="center">
        </el-table-column>
        <el-table-column prop="bookName" label="借阅书籍" width="130" align="center">
        </el-table-column>
        <el-table-column prop="bookId" label="书籍编号" width="130" align="center">
        </el-table-column>
        <el-table-column prop="borrowTime" label="借阅时间" width="200" align="center">
        </el-table-column>
        <el-table-column prop="returnTime" label="归还期限" width="200" align="center">
        </el-table-column>
        <el-table-column prop="completionTime" label="还书日期" width="200" align="center">
        </el-table-column>
        <el-table-column label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="confirm(scope.row.id)">确认</el-button>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <el-pagination background layout="total,sizes,prev,pager,next,jumper"
      @size-change="handleSizeChange2"
      @current-change="handleCurrentChange2"
      :total="total2"
      :current-page="currentPage2"
      :page-size="pageSize2"
      :page-sizes="[5,10,15,20,30,40,50]"></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios"
export default {
  data () {
      return {
        tableDataBorrow:[],
        tableDataReturn:[],

        total1:0,
        currentPage1:1,
        pageSize1:5,
        json1:{},

        total2:0,
        currentPage2:1,
        pageSize2:5,
        json2:{},

        time:"",
        date:"",
      }
    },
    methods: {
      handleSizeChange1(val){
        this.$set(this.json1,"pageSize",val)
        this.getinfoB()
      },

      handleCurrentChange1(val){
        this.$set(this.json1,"page",val)
        this.getinfoB()
      },

      handleSizeChange2(val){
        this.$set(this.json2,"pageSize",val)
        this.getinfoR()
      },

      handleCurrentChange2(val){
        this.$set(this.json2,"page",val)
        this.getinfoR()
      },

      /* 同意借书请求 */
      agree(val){
        axios.put(this.url + "/admin/agree",{
          "id":val,
          "isAgree":1,
          "auditer":localStorage.getItem("username")
        }).then((res) => {
          if(res.data.code == 1){
            this.$message.success("同意借书")
            this.getinfoB()
            this.getinfoR()
          }
        }).catch(() => {
          this.$message.error("操作失败")
        });
      },

      confirm(val){
        axios.put(this.url + "/admin/confirm",{
          "id":val,
          "isReturn":1,
          "auditer":localStorage.getItem("username")
        }).then((res) => {
          if(res.data.code == 1){
            this.$message.success("操作成功")
            this.getinfoB()
            this.getinfoR()
          }
        }).catch(() => {
          this.$message.error("操作失败")
        });
      },


      update_clock:function(){
            var d = new Date();
            var year = d.getFullYear();
            var mon = d.getMonth()+ 1;            
            var day = d.getDate();            
            var hour = d.getHours();            
            var minu = d.getMinutes();
            var sec = d.getSeconds();
            if(year<10){
                year = "0" + year;
            }
            if(mon<10){
                mon = "0" + mon;
            }
            if(day<10){
                day = "0" + day;
            }
            if(hour<10){
                hour = "0" + hour;
            }
            if(minu<10){
                minu = "0" + minu;
            }
            if(sec<10){
                sec = "0" + sec;
            }
            this.time = hour + ":" + minu + ":" + sec;
            this.date = year + "-" + mon + "-" + day;            
        },

        getinfoB(){
            axios.post(this.url + "/borrow/borrowlist",this.json1).then((res) => {
            if(res.data.code == 1){
              this.tableDataBorrow = res.data.data.records
              this.total1 = res.data.data.total
            }
          }).catch(() => {
            this.$message.error("信息加载失败")
          });

        },
        getinfoR(){
          axios.post(this.url + "/borrow/borrowlist",this.json2).then((res) => {
            if(res.data.code == 1){
              this.tableDataReturn = res.data.data.records
              this.total2 = res.data.data.total
            }
          }).catch(() => {
            this.$message.error("信息加载失败")
          });
        },
    },
    mounted () {
      this.update_clock()
      this.$set(this.json1,"page",this.currentPage1)
      this.$set(this.json1,"pageSize",this.pageSize1)
      this.$set(this.json1,"isAgree",0)
      this.$set(this.json2,"page",this.currentPage2)
      this.$set(this.json2,"pageSize",this.pageSize2)
      this.$set(this.json2,"isReturn",2)
      axios.post(this.url + "/borrow/borrowlist",this.json1).then((res) => {
        if(res.data.code == 1){
          this.tableDataBorrow = res.data.data.records
          this.total1 = res.data.data.total
        }
      }).catch(() => {
        this.$message.error("信息加载失败")
      });
      axios.post(this.url + "/borrow/borrowlist",this.json2).then((res) => {
        if(res.data.code == 1){
          this.tableDataReturn = res.data.data.records
          this.total2 = res.data.data.total
        }
      }).catch(() => {
        this.$message.error("信息加载失败")
      });
      /* 一秒调用一次 ，时钟*/
      this.$nextTick(()=>(
            setInterval(this.update_clock,1000)
        ));

    }
}
</script>

<style scoped>

</style>